package jvm.chapter2;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

/**
 * @program: algorithm
 * @description: VM Args: -Xmx20M -XX:MaxDirectMemorySize=10M
 * @author: 陈恩涛
 * @create: 2021-10-17 22:01
 **/
public class DirectMemoryOOM {

    private static final int _1MB = 1024 * 1034;

    public static void main(String[] args) throws IllegalAccessException {
        Field[] declaredFields = Unsafe.class.getDeclaredFields();
        Field unsafeField = declaredFields[0];
        unsafeField.setAccessible(true);
//        System.out.println(unsafeField.getName());
        Unsafe unsafe = (Unsafe) unsafeField.get(null);
        while (true) {
            unsafe.allocateMemory(_1MB);
        }

    }
}
